import MyComponent from "../classes/MyComponent.js";
import {MyMBR, MyDeviceDisk} from "./MySystem.js";
import {generateElement} from "../functions/common.js";

export class DiskInfo extends MyComponent{
    constructor(myDeviceDisk){
        super();
        this.myDeviceDisk = null;
        this.MBR = null;
        this.partitions = [];
        // <div style="height: 100px; background-color: #f2f2f2; ">
        this.elem = generateElement({
            type: "div",
            height: "100px",
            backgroundColor: "#f2f2f2",
        });
        if (myDeviceDisk instanceof MyDeviceDisk){
            this.MBR = myDeviceDisk.MBR;
            this.partitions = myDeviceDisk.partitions;
        }
        let lenTotal = 780, lenOfInfo = 100;
        if (this.MBR instanceof MyMBR){
            let dpt = this.MBR.dpt;
            let len = dpt.length;
            let lenOfPartition = len+1;
            let lenOf15 = lenOfPartition+1;
            let sizeOfDisk = dpt[len-1].begin + dpt[len-1].size;
            let blockWidth = (lenTotal - lenOfInfo * lenOfPartition - 15 * lenOf15)/sizeOfDisk;
            this.elem.appendChild(generateElement({
                type: "div",
                width: lenOfInfo.toString() + "px",
                margin: "15px 0px",
                marginLeft: "15px",
                innerText: "DiskInfo",
                display: "inline-block",
            }));
            for (let i = 0;i<len;i++){
                // <div style="width: 200px; height: 70px; display: inline-block; margin: 15px 0; margin-left:15px; background-color: #00F7DE">ABC</div>
                this.elem.appendChild(generateElement({
                    type: "div",
                    width: (blockWidth * dpt[i].size + lenOfInfo).toString() + "px",
                    height: "70px",
                    margin: "15px 0px",
                    marginLeft: "15px",
                    backgroundColor: "#00F7DE",
                    display: "inline-block",
                    innerText: dpt[i].type,
                }))
            }
        }
    }
}